﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;

namespace AutoR.ViewModels.Tasks
{
	// Token: 0x0200007E RID: 126
	public class SelectEquipmentViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x17000078 RID: 120
		// (get) Token: 0x06000211 RID: 529 RVA: 0x000456C7 File Offset: 0x000438C7
		private INavigationService NavigationService { get; }

		// Token: 0x17000079 RID: 121
		// (get) Token: 0x06000212 RID: 530 RVA: 0x000456CF File Offset: 0x000438CF
		private IPageDialogService PageDialogService { get; }

		// Token: 0x1700007A RID: 122
		// (get) Token: 0x06000213 RID: 531 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x1700007B RID: 123
		// (get) Token: 0x06000214 RID: 532 RVA: 0x000456D7 File Offset: 0x000438D7
		// (set) Token: 0x06000215 RID: 533 RVA: 0x000456E0 File Offset: 0x000438E0
		public RuleFleet Rule
		{
			[CompilerGenerated]
			get
			{
				return this.<Rule>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Rule>k__BackingField, value))
				{
					return;
				}
				this.<Rule>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Rule);
			}
		}

		// Token: 0x1700007C RID: 124
		// (get) Token: 0x06000216 RID: 534 RVA: 0x00045710 File Offset: 0x00043910
		// (set) Token: 0x06000217 RID: 535 RVA: 0x00045718 File Offset: 0x00043918
		public int ShipType
		{
			[CompilerGenerated]
			get
			{
				return this.<ShipType>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<ShipType>k__BackingField == value)
				{
					return;
				}
				this.<ShipType>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.ShipType);
			}
		}

		// Token: 0x1700007D RID: 125
		// (get) Token: 0x06000218 RID: 536 RVA: 0x00045745 File Offset: 0x00043945
		// (set) Token: 0x06000219 RID: 537 RVA: 0x00045750 File Offset: 0x00043950
		public List<UserEquipment> Equip
		{
			[CompilerGenerated]
			get
			{
				return this.<Equip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equip>k__BackingField, value))
				{
					return;
				}
				this.<Equip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equip);
			}
		}

		// Token: 0x1700007E RID: 126
		// (get) Token: 0x0600021A RID: 538 RVA: 0x00045780 File Offset: 0x00043980
		// (set) Token: 0x0600021B RID: 539 RVA: 0x00045788 File Offset: 0x00043988
		public int SelectedEquip
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectedEquip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<SelectedEquip>k__BackingField == value)
				{
					return;
				}
				this.<SelectedEquip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectedEquip);
			}
		}

		// Token: 0x1700007F RID: 127
		// (get) Token: 0x0600021C RID: 540 RVA: 0x000457B5 File Offset: 0x000439B5
		public DelegateCommand<string> SelectEquipCommand { get; }

		// Token: 0x17000080 RID: 128
		// (get) Token: 0x0600021D RID: 541 RVA: 0x000457BD File Offset: 0x000439BD
		public DelegateCommand EquipRemoveCommand { get; }

		// Token: 0x0600021E RID: 542 RVA: 0x000457C8 File Offset: 0x000439C8
		public SelectEquipmentViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.<SelectedEquip>k__BackingField = 1;
			base..ctor();
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.SelectEquipCommand = new DelegateCommand<string>(delegate(string s)
			{
				this.SelectedEquip = Convert.ToInt32(s);
			});
			this.EquipRemoveCommand = new DelegateCommand(delegate()
			{
				switch (this.SelectedEquip)
				{
				case 1:
					this.Rule.Equipment1 = 0;
					return;
				case 2:
					this.Rule.Equipment2 = 0;
					return;
				case 3:
					this.Rule.Equipment3 = 0;
					return;
				case 4:
					this.Rule.Equipment4 = 0;
					return;
				default:
					return;
				}
			});
		}

		// Token: 0x0600021F RID: 543 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x06000220 RID: 544 RVA: 0x0004581E File Offset: 0x00043A1E
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("rule"))
			{
				this.Rule = (RuleFleet)parameters["rule"];
				this.GenEquipList();
			}
		}

		// Token: 0x06000221 RID: 545 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x06000222 RID: 546 RVA: 0x0004584C File Offset: 0x00043A4C
		public void GenEquipList()
		{
			if (this.Rule != null)
			{
				List<UserEquipment> source = this.Rule.Equipped ? this.Game.GetEquipmentList() : this.Game.Equipments.ToList<UserEquipment>();
				if (this.ShipType != 0)
				{
					int[] id = new int[]
					{
						0,
						1,
						2,
						3,
						4,
						5,
						6,
						7,
						8,
						9,
						10,
						11,
						12,
						13,
						14,
						15,
						16,
						23,
						24
					};
					source = (from i in source
					where i.ShipType.Contains((ShipType)id[this.ShipType])
					select i).ToList<UserEquipment>();
				}
				this.Equip = (from i in source
				where i.num > 0
				orderby i.Type, i.Star
				select i).ToList<UserEquipment>();
			}
		}

		// Token: 0x06000223 RID: 547 RVA: 0x0004594C File Offset: 0x00043B4C
		public void EquipListView_OnSelectionChanged(UserEquipment select)
		{
			switch (this.SelectedEquip)
			{
			case 1:
				this.Rule.Equipment1 = select.equipmentCid;
				return;
			case 2:
				this.Rule.Equipment2 = select.equipmentCid;
				return;
			case 3:
				this.Rule.Equipment3 = select.equipmentCid;
				return;
			case 4:
				this.Rule.Equipment4 = select.equipmentCid;
				return;
			default:
				return;
			}
		}
	}
}
